package com.mycat.common.entity;

/**
 * @param <T>
 */
public class InvokeResult<T> {
    private int code;
    private String msg;
    private boolean hasErrors;
    private T data;

    public static InvokeResult success(){
        InvokeResult invokeResult = new InvokeResult();
        invokeResult.setMsg("提交成功!");
        invokeResult.setCode(200);
        invokeResult.hasErrors = false;

        return invokeResult;
    }

    public static InvokeResult success(Object data){
        InvokeResult invokeResult = new InvokeResult();
        invokeResult.setData(data);
        invokeResult.setCode(200);
        invokeResult.setMsg("提交成功!");
        invokeResult.hasErrors = false;

        return invokeResult;
    }

    public static InvokeResult failure(String msg){
        InvokeResult invokeResult = new InvokeResult();
        invokeResult.setCode(400);
        invokeResult.setMsg(msg);
        invokeResult.hasErrors = true;

        return invokeResult;
    }

    public static InvokeResult failure(int code,String msg){
        InvokeResult invokeResult = new InvokeResult();
        invokeResult.setCode(code);
        invokeResult.setMsg(msg);
        invokeResult.hasErrors = true;

        return invokeResult;
    }

    public static InvokeResult error(){
        InvokeResult invokeResult = new InvokeResult();
        invokeResult.setCode(500);
        invokeResult.setMsg("服务内部错误!");
        invokeResult.hasErrors = true;

        return invokeResult;
    }

    public static InvokeResult pass_no_data(){
        InvokeResult invokeResult = new InvokeResult();
        invokeResult.setCode(201);
        invokeResult.setMsg("查询数据为空!");
        invokeResult.hasErrors = true;

        return invokeResult;
    }

    public boolean isSuccess() {
        return !hasErrors;
    }

    public boolean hasErrors() {
        return hasErrors;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}
